package algorithms;

import java.util.Date;
import java.util.Map;
import java.util.Map.Entry;

import producer.bean.OrderInfo;
import producer.impl.Producer;
/**
 * Algorytm wyszukukacy producentów po najwczesniejszej
 * dacie produkcji
 * @author Przemek Pioro
 *
 */
public class BestTime implements IAlgorithm {

	private Date bestTime = null;
	private Producer producer = null;
	@Override
	public Producer find(Map<Producer, OrderInfo> data) {
		bestTime = null;
		producer = null;
		for(Entry<Producer,OrderInfo> entry : data.entrySet()){
			if(bestTime == null){
				bestTime = entry.getValue().getFinishDate();
			}
			else {
				if(entry.getValue().getFinishDate().before(bestTime)){
					bestTime = entry.getValue().getFinishDate();
					producer = entry.getKey();
				}
			}
		}
		return producer;
	}

}
